package com.nmsl.masterdocker.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.masterdocker.domain.Cure;
import com.nmsl.masterdocker.service.ICureService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 治疗方案Controller
 * 
 * @author ruoyi
 * @date 2025-02-21
 */
@RestController
@RequestMapping("/masterdocker/cure")
public class CureController extends BaseController
{
    @Autowired
    private ICureService cureService;

    /**
     * 查询治疗方案列表
     */
    @PreAuthorize("@ss.hasPermi('masterdocker:cure:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cure cure)
    {
        startPage();
        List<Cure> list = cureService.selectCureList(cure);
        return getDataTable(list);
    }

    /**
     * 导出治疗方案列表
     */
    @PreAuthorize("@ss.hasPermi('masterdocker:cure:export')")
    @Log(title = "治疗方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cure cure)
    {
        List<Cure> list = cureService.selectCureList(cure);
        ExcelUtil<Cure> util = new ExcelUtil<Cure>(Cure.class);
        util.exportExcel(response, list, "治疗方案数据");
    }

    /**
     * 获取治疗方案详细信息
     */
    @PreAuthorize("@ss.hasPermi('masterdocker:cure:query')")
    @GetMapping(value = "/{cureId}")
    public AjaxResult getInfo(@PathVariable("cureId") Long cureId)
    {
        return success(cureService.selectCureByCureId(cureId));
    }

    /**
     * 新增治疗方案
     */
    @PreAuthorize("@ss.hasPermi('masterdocker:cure:add')")
    @Log(title = "治疗方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cure cure)
    {
        return toAjax(cureService.insertCure(cure));
    }

    /**
     * 修改治疗方案
     */
    @PreAuthorize("@ss.hasPermi('masterdocker:cure:edit')")
    @Log(title = "治疗方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cure cure)
    {
        return toAjax(cureService.updateCure(cure));
    }

    /**
     * 删除治疗方案
     */
    @PreAuthorize("@ss.hasPermi('masterdocker:cure:remove')")
    @Log(title = "治疗方案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cureIds}")
    public AjaxResult remove(@PathVariable Long[] cureIds)
    {
        return toAjax(cureService.deleteCureByCureIds(cureIds));
    }

    @GetMapping("/allCure")
    public TableDataInfo allCure()
    {
        Page page = mystartPage();
        List<Cure> list = cureService.selectAllCure();
        return mygetDataTable(list, page.toPageInfo());
    }
}
